package com.cfwx.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * 客户端程序，从控制台输入字符，向服务器发出请求并得到响应
 * @author Administrator
 *
 */
public class MyClient {
	Socket socket;
	BufferedReader in;
	PrintWriter out;
	public MyClient()
	{
		try
		{
			BufferedReader line = new BufferedReader(new InputStreamReader(System.in));
			String readLine = line.readLine();
			while(!readLine.equals("bye")){
				socket = new Socket("127.0.0.1", 9991);
				in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				out = new PrintWriter(socket.getOutputStream(),true);
				out.println(readLine);//向服务端输出由控制台输入的字符
				String resp = in.readLine();//得到来自服务端的应答
				System.out.println("server:"+resp);
				readLine=line.readLine(); //继续从系统标准输入读入一字符串
			}
			line.close();
			out.close();
			in.close();
			socket.close();
			System.out.println("客户端结束！");
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}

	}
	public static void main(String[] args)
	{
		new MyClient();
	}
}
